Process Overview
STEP 1 - Trigger & Branching
- When the Run AML Check* button is clicked in Practice Gateway, JavaScript checks the Run SmartDoc Check* field.
- If Yes → trigger Power Automate flow
SmartSearch - Run a SmartDoc Check. - If No → follow the regular process: start
SmartSearch - Run a UK Individual AMLand do NOT start the SmartDoc process.
- If Yes → trigger Power Automate flow
* Run AML Check - is a button on the Practice Gateway model driven app. The following js file updates on KYC-Commands.js were made to start the SmartSearch - Run a SmartDoc Check flow:
120 const environmentVariableNameAPIRunaSmartDocCheck = "tt_APIRunaSmartDocCheck";
465
// Location: tt_ukindividualaml form
async function KYCForIndividuals_RunAMLCheck(formContext, amlIDWithBraces) {
await formContext.data.save(); // ensure data is saved before we do anything
try {
// Get SRA ID from the current AML form lookup
const sraLookup = formContext.getAttribute("tt_kyccheck")?.getValue();
if (!sraLookup || !sraLookup.length) {
formContext.ui.setFormNotification("Related Specific Risk Assessment (SRA) not found.", "ERROR");
return;
}
const sraId = sraLookup[0].id.slice(1, -1);
// Retrieve the tt_runsmartdoccheck value from SRA record
const sraData = await retrieveWebAPIData(
"tt_kycchecks", // entity name (plural)
"tt_runsmartdoccheck", // field to retrieve
`tt_kyccheckid eq ${sraId}`, // filter
""
);
const runSmartDocCheck = sraData?.value?.[0]?.tt_runsmartdoccheck;
console.log("tt_runsmartdoccheck value:", runSmartDocCheck);
if (runSmartDocCheck === true) {
const confirmStrings = {
text: "I confirm that the UK Individual AML information provided by the client is correct to the best of my knowledge and I approve this identity verification process.",
title: "Validation Confirmation"
};
const success = await Xrm.Navigation.openConfirmDialog(confirmStrings);
if (!success.confirmed) return false;
// Get UK Individual AML id
if (!amlIDWithBraces) throw new Error("AML ID not provided.");
const amlID = amlIDWithBraces.slice(1, -1);
// Notify user
const notifInProgress = "notifSmartDocCheck";
formContext.ui.setFormNotification("Starting SmartDoc process...", "INFORMATION", notifInProgress);
// Run SmartDoc check flow
const url = GetEnvironmentVariableValue(environmentVariableNameAPIRunaSmartDocCheck);
const dataAML = { "UK Individual AML": amlID };
const response = await RunFlow(url, dataAML);
const responseObj = await response.json();
formContext.ui.clearFormNotification(notifInProgress);
if (response.status === 200) {
formContext.ui.setFormNotification("SmartDoc process has been started. Results data will be available in the \"AML Check Results\" tab after the user completes their facial recognition steps.", "INFO");
}
else if (response.status === 400) {
const smartSearchError = new SmartSearchError(responseObj.errorDetail);
smartSearchError.responseObj = responseObj;
throw smartSearchError;
}
else {
console.error(responseObj);
formContext.ui.setFormNotification("SmartDoc check failed. Please contact support.", "ERROR");
}
return;
}
const confirmStrings = {
text: "I confirm that the UK Individual AML information provided by the client is correct to the best of my knowledge and I approve this identity verification process.",
title: "Validation confirmation"
};
const success = await Xrm.Navigation.openConfirmDialog(confirmStrings);
if (!success.confirmed) return false;
// Get UK Individual AML id
if (!amlIDWithBraces) throw new Error("AML ID not provided.");
const amlID = amlIDWithBraces.slice(1, -1);
// Notify user
const notifInProgress = "notifRunAMLCheck";
formContext.ui.setFormNotification("Running UK Individual AML check...", "INFORMATION", notifInProgress);
// Run AML check flow
const url = GetEnvironmentVariableValue(environmentVariableNameAPIRunUKIndividualAML);
const dataAML = { "UK Individual AML": amlID };
const response = await RunFlow(url, dataAML);
const responseObj = await response.json();
// Handle response
await formContext.data.refresh();
formContext.ui.clearFormNotification(notifInProgress);
if (response.status === 200) {
formContext.ui.setFormNotification("UK Individual AML check complete. Results data is available in the \"AML Check Results\" tab. Results PDF saved to Documents.", "INFO");
} else if (response.status === 400) {
const smartSearchError = new SmartSearchError(responseObj.errorDetail);
smartSearchError.responseObj = responseObj;
throw smartSearchError;
} else {
throw new Error("Unexpected response from AML check flow.");
}
// Get parent SRA id from AML
const sraValueObject = retrieveWebAPIData(
"tt_ukindividualamls",
"_tt_kyccheck_value",
`tt_ukindividualamlid eq '${amlID}'`,
""
);
if (!sraValueObject?.value?.length) throw new Error("SRA ID not found");
const relatedSraId = sraValueObject.value[0]._tt_kyccheck_value;
// Update SRA record
const entityNamePlural = "tt_kycchecks";
const userId = Xrm.Utility.getGlobalContext().userSettings.userId.slice(1, -1);
const utcDateString = new Date().toISOString();
const dataSRA = {
"tt_AMLCheckApprovalUser@odata.bind": `/systemusers(${userId})`,
"tt_amlcheckapprovalcompletedon": utcDateString
};
PatchWebAPIData(entityNamePlural, dataSRA, relatedSraId);
} catch (error) {
if (error instanceof SmartSearchError) {
const { errorDetail, errorSource, notificationMessage, notificationLevel } = error.responseObj;
console.error(errorDetail);
if (errorSource === "SmartSearch") {
errorDetail.forEach((errorRow) => {
const translatedMessage = `Validation error with ${errorRow.source.pointer.replace("/data/attributes", "")}. ${errorRow.detail}`;
formContext.ui.setFormNotification(translatedMessage, notificationLevel);
});
} else {
formContext.ui.setFormNotification(notificationMessage, notificationLevel);
}
} else {
console.error(error);
formContext.ui.setFormNotification("Something went wrong. Please contact your Practice Gateway support team.", "ERROR");
}
}
}
604
* Run SmartDoc Check - is a toggle (Yes/No Choice) field on the Specific Risk Assessment forms (Base, Main, PMS). Default value of this field is set using an environment variable called SmartSearch - Run SmartDoc Check in order to allow certain clients to have SmartDoc Check process either enabled or disabled by default. Default value is set using JavaScript when a new form is being created by either using the Start New KYC button on the model driven app ribbon or clicking on + New Specific Risk Assessment button under the Specific Risk Assessment subgrid. The following js file updates were made:
- To set default value when using + New Specific Risk Assessment button under the Specific Risk Assessment subgrid - the following code was added on KYCCheck.js:
517 this.SetRunSmartdocCheckDefault();
880
SetRunSmartdocCheckDefault() {
if (logMethodCalls) console.log(`%c SpecificRiskAssessment.SetRunSmartdocCheckDefault()`, "color: Gold; font-size: 12px");
console.log("==== SetRunSmartdocCheckDefault START ====");
try {
const envVarSchemaName = "tt_SmartSearchRunSmartDocCheck";
console.log(`[RunSmartdocCheck] Reading environment variable: ${envVarSchemaName}`);
// Get the environment variable value - TRY MULTIPLE METHODS
let envVarValue;
// Method 1: Try GetEnvironmentVariableValue (if it exists)
try {
if (typeof GetEnvironmentVariableValue !== 'undefined') {
envVarValue = GetEnvironmentVariableValue(envVarSchemaName);
console.log(`[RunSmartdocCheck] Method 1 (GetEnvironmentVariableValue) returned:`, envVarValue, `(type: ${typeof envVarValue})`);
} else {
console.warn("[RunSmartdocCheck] GetEnvironmentVariableValue function not found");
}
} catch (e) {
console.error("[RunSmartdocCheck] GetEnvironmentVariableValue error:", e);
}
// Method 2: Try GetSettingValue (alternative)
if (envVarValue === undefined || envVarValue === null) {
try {
if (typeof GetSettingValue !== 'undefined') {
envVarValue = GetSettingValue(envVarSchemaName);
console.log(`[RunSmartdocCheck] Method 2 (GetSettingValue) returned:`, envVarValue, `(type: ${typeof envVarValue})`);
}
} catch (e) {
console.error("[RunSmartdocCheck] GetSettingValue error:", e);
}
}
console.log(`[RunSmartdocCheck] Final environment variable value:`, envVarValue, `(type: ${typeof envVarValue})`);
// Get the toggle attribute
const toggleAttribute = this.formContext.getAttribute("tt_runsmartdoccheck");
if (!toggleAttribute) {
console.warn("[RunSmartdocCheck] Toggle field 'tt_runsmartdoccheck' not found on form.");
console.log("==== SetRunSmartdocCheckDefault END (field not found) ====");
return;
}
console.log("[RunSmartdocCheck] Toggle field found successfully");
// Check current value
const currentValue = toggleAttribute.getValue();
console.log(`[RunSmartdocCheck] Current toggle value:`, currentValue, `(type: ${typeof currentValue})`);
// Check form mode
console.log(`[RunSmartdocCheck] Form mode:`, this.formMode, "(1=Create, 2=Update)");
// Only set default if the field is currently null/undefined AND we're in create mode
if (this.formMode !== 1) {
console.log("[RunSmartdocCheck] Function only applies on New Forms, skipping.");
console.log("==== SetRunSmartdocCheckDefault END (Not a New Form) ====");
return;
}
// Parse the environment variable value
// Accept: true, "true", "yes", "1", 1 as YES
// Everything else as NO
const shouldEnableSmartdoc =
envVarValue === true ||
envVarValue === 1 ||
String(envVarValue).toLowerCase() === "true" ||
String(envVarValue).toLowerCase() === "yes" ||
String(envVarValue) === "1";
console.log(`[RunSmartdocCheck] Calculated shouldEnableSmartdoc:`, shouldEnableSmartdoc);
// Set the toggle value (true = Yes, false = No)
toggleAttribute.setValue(shouldEnableSmartdoc);
// Verify it was set
const newValue = toggleAttribute.getValue();
console.log(`[RunSmartdocCheck] Value after setting:`, newValue);
} catch (error) {
console.error("[RunSmartdocCheck] ERROR in SetRunSmartdocCheckDefault:", error);
console.error("[RunSmartdocCheck] Error stack:", error.stack);
}
console.log("==== SetRunSmartdocCheckDefault END ====");
}
970
- To set default value when using the Start New KYC button on the model driven app ribbon - the following code was added on KYC-Commands.js:
129 const environmentVariableNameSmartDocEnabled = "tt_SmartSearchRunSmartDocCheck"
245
// Get environment variable value for the "Run SmartDoc Check" field
const runSmartDocCheckEnvironmentVariableValue = GetEnvironmentVariableValue(environmentVariableNameSmartDocEnabled);
if (runSmartDocCheckEnvironmentVariableValue == "yes") {
runSmartDocCheck = true;
} else {
runSmartDocCheck = false;
}
console.log("runSmartDocCheck: " + runSmartDocCheck);
254
265 "tt_runsmartdoccheck": runSmartDocCheck
STEP 2 - Primary SmartDoc Flow (SmartSearch - Run a SmartDoc Check)
- Retrieve UK Individual AML record to get the first part of the required details.
- If not found →
InputError→ Unable to find UK Individual AML row.
- If not found →
- Retrieve Contact record to obtain the second part of the required details.
- Get SmartSearch access token.
- If retrieval fails →
AuthenticationFailure→ Unable to retrieve SmartSearch access token.
- If retrieval fails →
- Fetch passport document file.
- If not found or retrieval fails → Passport file was not found → Unable to find passport file. Please contact your Practice Gateway support team.
- Call Run a SmartDoc Check API.
- If the API call fails → Unable to create a SmartDoc record. Please contact your Practice Gateway support team.
- Call Add a document to a SmartDoc API.
- If the API call fails → Unable to add a document to a SmartDoc. Please contact your Practice Gateway support team.
- Call Add an image to a document API.
- If the API call fails → Unable to add an image to a document. Please contact your Practice Gateway support team.
- Call Send email notification to the customer API.
- If sending fails → Unable to add an image to a document. Please contact your Practice Gateway support team.
- If sending is successful - client will get an email notification sent to them, which they MUST open on a mobile device to be able to complete the facial recognition steps.
- SmartDoc will have a Pending status until client completes their facial recognition steps.
- After client completes their facial recognition steps on a mobile device, SmartDoc record will automatically get submitted for document verification and will produce and outcome shortly after.
- The outcome of the SmartDoc Check will not be obtained at this stage, but will be handeled by another flow -
SmartSearch - Check in-progress SmartDoc itemswhich is covered later in this documentation.
- Update UK Individual AML record with details gathered:
- SmartDoc Created On
- SmartDoc Document ID
- SmartDoc Document Image ID
- SmartDoc ID
- SmartDoc Notification Expiry Date
- SmartDoc Notification ID
- SmartDoc Status
- SmartDoc Status Date
- SmartDoc Subject ID
STEP 3 - Daily Monitoring Flow (SmartSearch - Check in-progress SmartDoc items)
- Runs daily, selecting UK Individual AML records with SmartDoc status
PendingorProcessing.- If no items are found → flow terminates.
- Otherwise - Get SmartSearch access token.
- If retrieval fails →
AuthenticationFailure→ Unable to retrieve SmartSearch access token.
- If retrieval fails →
- Retrieve the SmartDoc Check associated with each UK Individual AML record that was retrieved.
- Based on the SmartDoc status and whether the previously sent notification has expired or not, the flow chooses one of four paths:
PATH 1 — no_action
- Take no action if:
- SmartDoc status is
Pending, AND - Notification has NOT expired.
- SmartDoc status is
PATH 2 — expired_pending
-
If:
- SmartDoc status is
Pending, AND - Notification HAS expired.
- SmartDoc status is
-
Get Contact and Manager details and send an email to the Manager (using
SmartSearch - Send an email to contacts manager) with options:- Send New Notification, OR
- Cancel Verification
-
Outcomes:
- If Manager does not respond within 5 days → Cancel document verification process.
- If Manager selects Send New Notification → send a new email to the client giving another 5 days to complete verification.
- If Manager selects Cancel Verification → Cancel document verification process.
PATH 3 — completed
- Save the result on the UK Individual AML record.
- Result can be viewed on the AML Check Results tab, which will display:
- SmartDoc Status - status of the actual process.
- SmartDoc Outcome - result of the document verification.
- SmartDoc Response - any details in case the outcome failed.
- Result can be viewed on the AML Check Results tab, which will display:
- Start the
SmartSearch - Run a UK Individual AML flow; the SmartDoc process ends here.
PATH 4 — other outcomes (failed, expired, abandoned)
- Update the UK Individual AML record noting that the SmartDoc process failed.
Error Handling
- Under any error, the flow sends an email to T-Tech IT Support email which will be set on the T-Tech Support Email environment variable.